#include "forgetpasswordwidget.h"
#include "ui_forgetpasswordwidget.h"

ForgetPasswordWidget::ForgetPasswordWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::ForgetPasswordWidget)
{
    ui->setupUi(this);
    loadStyleSheet("C:/Users/shafl/Desktop/IoTDeviceManage/src/css/img.css");
    connect(ui->bntResetQuit,&QPushButton::clicked,this,[=](){
        emit selectStackWidget(0);
    });
}

ForgetPasswordWidget::~ForgetPasswordWidget()
{
    delete ui;
}

void ForgetPasswordWidget::loadStyleSheet(const QString &CssPath)
{
    QFile file(CssPath);
    if(!file.open(QIODevice::ReadWrite)){
        qDebug() << "open file failed";
        return;
    }
    this->setStyleSheet(file.readAll());
}

void ForgetPasswordWidget::onGetCode()
{

}

void ForgetPasswordWidget::onVerifyReset()
{
    Phone = ui->linePhonePassReset->text();
    NewPass = ui->lineNewPass->text();
    QString LineIdfCode = ui->lineidfcode->text();
    if(Phone.isEmpty()||IdfCode.isEmpty()||NewPass.isEmpty()){
        emit sendMessage("内容不能为空");
        return;
    }
    if (!sqlOperator.openDatabase("C:/Users/shafl/Desktop/FrameWork/test.db")) {
        qDebug() << "Failed to open database:" << sqlOperator.lastError();
        emit sendMessage("数据库连接错误");
        return;
    }
    QList<QVariantMap> users = sqlOperator.selectData("users","phone='" + Phone + "'");
    if(users.isEmpty()){
        emit sendMessage("不存在用户:"+Phone);
        ui->linePhonePassReset->clear();
        sqlOperator.closeDatabase();
        return;
    }
    //验证码对比-------------
    //LineIdfCode == IdfCode
    //密码加密
    //修改数据库，跳转主界面
    //=====================

}

